package com.glsx.auto;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by linxy on 2017/4/28.
 */
public class TableFactory {
    private Connection connection;

    private String url;
    private String username;
    private String password;

    public TableFactory(String url, String username, String password) {
        this.url = url;
        this.username = username;
        this.password = password;
    }

    public Table fetchTable(String tableName, String erasePrefix) throws SQLException {
        if(connection == null) {
            connection = DriverManager.getConnection("jdbc:mysql://" + url + "?useUnicode=true&characterEncoding=UTF-8", username, password);
        }

        Table table = new Table(tableName, erasePrefix);
        table.populateColumn(connection);

        return table;
    }
}
